﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SwHelper.Modle;
using SolidWorks.Interop.sldworks;
using SwHelper.ModleView;

namespace SwUI.Modle
{
    public class NodeOfComponentIm
    {

        public static void CreateComponentTree(NodeOfComponent cponent, List<NodeOfComponent> lists)
        {
            object[] comObj = cponent.component.GetChildren();
            foreach (Component2 cp in comObj)
            {
                NodeOfComponent node = new NodeOfComponent();
                node.nodeName = cp.Name2;
                node.fullPath = cp.GetPathName();
                node.nodeTag = node;
                node.component = cp;
                node.parentNodeTag = cponent.nodeTag;
                lists.Add(node);
                CreateComponentTree(node, lists);
            }
        }

        public static void SortAndUnique(List<NodeOfComponent> lists, out List<NodeOfComponent> uniquePartList)
        {
            uniquePartList = new List<NodeOfComponent>();
            HashSet<string> uniquePath = new HashSet<string>();
            foreach(NodeOfComponent node in lists)
            {
                bool isUnique =  uniquePath.Add(node.fullPath);
                if (isUnique)
                {
                    node.nodeCount = 1;
                    uniquePartList.Add(node);
                }else
                {
                    foreach(NodeOfComponent node2 in uniquePartList)
                    {
                        if (node2.fullPath == node.fullPath)
                        {
                            node2.nodeCount++;
                        }                                             
                    }
                }
            }

        }

    }
}
